﻿
﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
﻿using OilRigSumoWrestlers.Controllables.Controllers;
﻿using OilRigSumoWrestlers.Entities.MenuItems;
using RaptorEngine;
using RaptorEngine.Components.Drawable;

﻿namespace OilRigSumoWrestlers.Scenes.Menu

{
    public class MultiplayerMenu:MenuScene
    {
        public MultiplayerMenu()
            : base(false)
        {
            CreateHUD();
            CreateController();
        }
        private void CreateHUD()
        {
            Vector2 worldCenter = new Vector2(
                GameEngine.Instance.Render.GraphicsDevice.Viewport.TitleSafeArea.X + GameEngine.Instance.Render.GraphicsDevice.Viewport.TitleSafeArea.Width / 2,
                GameEngine.Instance.Render.GraphicsDevice.Viewport.TitleSafeArea.Y + GameEngine.Instance.Render.GraphicsDevice.Viewport.TitleSafeArea.Height / 2);

            //Text displayed with a "shadow"
            string multiplayerMenuText = "Multiplayer";

            Entity multiplayerMenu = new Entity(worldCenter + new Vector2(0, -60));
            multiplayerMenu.AddComponent(new DrawableText(multiplayerMenu, 
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuFont"), multiplayerMenuText, Color.White, 1, true));

            Entity multiplayerMenuShadow = new Entity(worldCenter + new Vector2(0, -60)+Vector2.One);
            multiplayerMenuShadow.AddComponent(new DrawableText(multiplayerMenuShadow,
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuFont"), multiplayerMenuText, Color.Black, 1, true));

            //Add texts to the scene
            AddEntity(multiplayerMenuShadow);
            AddEntity(multiplayerMenu);
           
            //Multiplayer text
            string multiplayerLocalText = "Local Game";

            DrawableText optMultiplayerLocalSelected = new DrawableText(new Entity(worldCenter + new Vector2(0, 40)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), multiplayerLocalText, Color.White, 1, true);

            DrawableText optMultiplayerLocal = new DrawableText(new Entity(worldCenter + new Vector2(0, 40)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), multiplayerLocalText, Color.Gray, 1, true);
            
            //Start Game text
            string multiplayerP2PText = "Network Game";

            DrawableText optMultiplayerP2PSelected = new DrawableText(new Entity(worldCenter + new Vector2(0, 80)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), multiplayerP2PText, Color.White, 1, true);

            DrawableText optMultiplayerP2P = new DrawableText(new Entity(worldCenter + new Vector2(0, 80)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), multiplayerP2PText, Color.Gray, 1, true);

            //Exit Game text
            string backText = "Back";

            DrawableText optBackSelected = new DrawableText(new Entity(worldCenter + new Vector2(0, 120)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), backText, Color.White, 1, true);

            DrawableText optBack = new DrawableText(new Entity(worldCenter + new Vector2(0, 120)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), backText, Color.Gray, 1, true);

            _menuItems.Add(new MultiplayerLocalItem(optMultiplayerLocalSelected, optMultiplayerLocal));
#if !XBOX
            _menuItems.Add(new MultiplayerP2PItem(optMultiplayerP2PSelected, optMultiplayerP2P));
#endif
            _menuItems.Add(new BackMenuItem(optBackSelected, optBack));
            _menuItems[_selectedItem].Select();

            foreach (MenuItem item in _menuItems)
            {
                AddEntity(item);
            }

        }

        private void CreateController()
        {
            Entity menuController = new Entity();
            menuController.AddComponent(new MenuControllable(menuController, this, RaptorEngine.Managers.LogicalPlayerIndex.One));
            AddEntity(menuController);
        }

        public override void GoBack()
        {
            GameEngine.Instance.Scene.RemoveCurrentScene();
            GameEngine.Instance.Scene.StartCurrentScene();
            GameEngine.Instance.Scene.ShowCurrentScene();
            base.GoBack();
        }

        public override void Update()
        {
            
        }
    }
}
